﻿using Acme.SmartWMS.BasicInfo.IClassificationService.DTO;
using Acme.SmartWMS.DataBasic;
using LiteDB;
using Microsoft.AspNetCore.Mvc;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using System;
using Acme.SmartWMS.BasicInfo.IClassificationService;

namespace Acme.SmartWMS.Web.Controllers.BasicInfo
{
    public class ClassificationController : Controller
    {
        private readonly IClassificationAppService _classificationAppService;

        public ClassificationController(IClassificationAppService classificationAppService)
        {
            _classificationAppService = classificationAppService;
        }

        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public async Task<int> Add(DictItemInsertDTO itemdto)
        {
            return await _classificationAppService.Add(itemdto);
        }

        /// <summary>
        /// 查询显示
        /// </summary>
        /// <param name="name"></param>
        /// <param name="limit"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetDictItem(string? name, int limit, int page)
        {
            var res = await _classificationAppService.GetDictItem(name, limit, page);
            return Json(new { data = res.Queryable,code = 0,count = res.RowCount});
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> Del(int id)
        {
            return await _classificationAppService.Del(id);
        }

        /// <summary>
        /// 查询单个
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<DictItemSelDTO> SelSing(int id)
        {
            return await _classificationAppService.SelSing(id);
        }

        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="itemdto"></param>
        /// <returns></returns>
        public async Task<int> Upd(DictItemUpdateDTO itemdto)
        {
            return await _classificationAppService.Upd(itemdto);
        }
    }
}
